import { ElMessage } from 'element-plus';

const getMenuTitleListByUserId = async (userId: number) => {
  try {
    const res = await api({
      url: `${urls.menu}/userId/${userId}`,
      method: 'get',
    });
    if (res.status === 200) {
      const resData = res.data;
      if (resData.status) {
        return resData.body;
      } else {
        ElMessage({
          message: resData.msg,
          type: resData.type,
        });
      }
    } else {
      ElMessage.error(res.statusText);
    }
  } catch (error) {
    ElMessage.error('获取失败，错误信息是：' + error);
    return false;
  }
};

export const getPermissionTextListByUserId = async (userId: number) => {
  try {
    const res = await api({
      url: urls.permission + `/userId/${userId}`,
      method: 'get',
    });
    if (res.status === 200) {
      const resData = res.data;
      if (resData.status) {
        return resData.body;
      } else {
        ElMessage({
          message: resData.msg,
          type: resData.type,
        });
      }
    } else {
      ElMessage.error(res.statusText);
    }
  } catch (error) {
    ElMessage.error('获取失败，错误信息是：' + error);
    return false;
  }
};
